<template>
	<div>
		<div class='prizeDrawSpace'>

		</div>
		<div class="prizeDraw">
			<div class="prizeDraw_top">
				<div class="prizeDraw_top_close">
					红包 <image src="@/static/image/close.png" mode="" class="closeImg" @click="closeDialog"> </image>
				</div>
				<scroll-view @scrolltolower="scrolltolower" :style="{ height: scrollViewHeight + 'rpx' }" :scroll-y="true"
					:scroll-with-animation="true">
					<div class="prizeDraw_user_item" v-for="(ite, idx) in RedList" :key='idx'>
						<div class='prizeDraw_user_item_top'>

							<div v-if="ite.status === 1" class="prizeDraw_user_item_top_left_btn_one">未支付</div>
							<div v-else-if="ite.status === 2" class="prizeDraw_user_item_top_left_btn_one">未领完
							</div>
							<div v-else-if="ite.status === 3"
								class="prizeDraw_user_item_top_left_btn_one_act prizeDraw_user_item_top_left_btn_one">已领完
							</div>
							<div v-else-if="ite.status === 4"
								class="prizeDraw_user_item_top_left_btn_one_act prizeDraw_user_item_top_left_btn_one">已过期
							</div>
							<div v-else>-</div>
							<div
								:class="ite.type == 1 ? 'prizeDraw_user_item_top_left_btn_two prizeDraw_user_item_top_left_btn_two_act' : 'prizeDraw_user_item_top_left_btn_two'">
								{{ ite.type == 1 ? '拼手气红包' : '普通红包' }}
							</div>
							<div class='prizeDraw_user_item_top_title ex'>
								{{ ite.desc }}
							</div>
						</div>
						<!-- 	<div class="prizeDraw_items_cont_items">
						<div class="prizeDraw_items_cont_items_left">
							红包总金额：¥<div class="prizeDraw_items_cont_items_cont ex">{{ite.prizeName}}</div>
						</div>
					</div> -->

						<div class="prizeDraw_items_cont_items">
							<div class="prizeDraw_items_cont_items_left">
								红包总金额：¥<div class="prizeDraw_items_cont_items_left_a ex">{{ (ite.amount / 100).toFixed(2) }}
								</div>
							</div>
							<div class="prizeDraw_items_cont_items_left textRight">
								剩余金额：¥<div class="prizeDraw_items_cont_items_left_a ex ">
									{{ ((ite.amount - ite.receivedAmount) / 100).toFixed(2) }}
								</div>
							</div>
						</div>
						<div class="prizeDraw_items_cont_items">
							<div class="prizeDraw_items_cont_items_left">
								剩余数量：<div class="prizeDraw_items_cont_items_left_a ex">
									{{ ite.num - ite.receivedNum }}/{{ ite.num }}
								</div>
							</div>
							<div class="prizeDraw_items_cont_items_left timeCont textRight">
								创建时间：<div class="prizeDraw_items_cont_items_left_a ex ">{{ ite.createTime | formatDate }}
								</div>
							</div>
						</div>
						<div class="prizeDraw_items_cont_items_btn" @click='receveEvent(ite)'>
							<image src="@/static/image/delete.png" mode=""></image>
							<div class="prizeDraw_items_cont_items_btn_text">
								领取记录
							</div>
						</div>
					</div>
					<div class="listSpace" v-if="RedList.length <= 0 && loading">
						<list-space></list-space>
					</div>
					<div class="zj_space">

					</div>
					<div class="zj_space">

					</div>
					<div class="zj_space">

					</div>
					<div class="zj_red_btn">
						<div class="zj_red_btn_cont" @click='sendRed()'>
							发红包
						</div>
					</div>

				</scroll-view>
			</div>
		</div>
	</div>
</template>

<script>
export default {
	filters: {
		formatDate(v) {
			const value = v * 1000
			const data = new Date(value);
			const month = data.getMonth() + 1;
			const day = data.getDate();
			const year = data.getFullYear();
			const hours = data.getHours();
			const minutes = data.getMinutes();
			const seconds = data.getSeconds();
			const formattedTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
			return formattedTime;
		}
	},
	data() {
		return {
			params: {
				page: 1,
				pageSize: 10,
				liveId: '1777987123102617600'
			},
			RedList: [],
			scrollViewHeight: 882,
			total: 0,
			Amount: 0, //余额
			loading: false,
			isRefresh: false
		}
	},
	onShow() {
		if (this.isRefresh) {
			console.log('isRefresh')
			this.RedList = []
			this.params.page = 1
			this.loading = false
			this.getDrawWinPrizeCustomer(1)
		}

	},
	onLoad(opt) {
		console.log('isRefreshonLoad')
		if (opt.liveId) {
			this.params.liveId = opt.liveId || this.liveId
		}
		this.RedList = []
		this.params.page = 1
		this.loading = false
		this.getDrawWinPrizeCustomer()
	},
	onPullDownRefresh() {
		this.RedList = []
		this.params.page = 1
		this.loading = false
		this.getDrawWinPrizeCustomer()
	},
	methods: {
		closeDialog() {
			this.$utils.closeDialog(this)
			// uni.navigateBack()
		},
		scrolltolower(e) {
			if (this.RedList.length < this.total) {
				this.params.page++
				this.getDrawWinPrizeCustomer()
			} else {
				uni.showToast({
					title: '已到底',
					icon: 'none'
				})
			}
			console.log('e.detail.scrollTop', e.detail.scrollTop)
		},
		async getDrawWinPrizeCustomer() {
			const {
				data
			} = await this.$request(this.$Api.redPacketList + "/" + this.params.liveId, this.params, "get")
			this.loading = true
			if (!data.data) return
			if (status == 1) {
				this.RedList = data.data
			} else {
				this.RedList = this.RedList.concat(data.data)
			}
			this.total = data.total
			uni.stopPullDownRefresh()
		},
		// 中奖名单
		winnersEvemt(ite) {

		},
		// 查看红包记录
		receveEvent(ite) {
			uni.navigateTo({
				url: '/pages/redPacket/RedEnvelopeCollectionRecord?redName=' + ite.desc + '&redPacketId=' + ite
					.redPacketId
			})

		},
		backEvent() {
			uni.navigateBack()
		},
		// 发红包
		sendRed() {
			this.isRefresh = false
			uni.navigateTo({
				url: '/pages/redPacket/sendRedPacket?liveId=' + this.params.liveId
			})
		}
	}
}
</script>

<style lang="scss">
.prizeDraw {
	width: 100%;
	height: 992rpx;
	background: #FFFFFF;
	border-radius: 16rpx 16rpx 0rpx 0rpx;
	overflow-y: hidden;
	// position: fixed;
	bottom: 0;
	left: 0;
	padding: 0 32rpx;
	box-sizing: border-box;
	color: #464C5B;
	font-size: 28rpx;

	.prizeDraw_top {
		width: 100%;
		height: 100rpx;
		position: relative;
		text-align: center;
		font-size: 32rpx;
		line-height: 100rpx;

		.prizeDraw_top_close_left {
			position: absolute;
			left: 0;
			top: 10rpx;
			width: 44rpx;
			height: 44rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}


		.closeImg {
			position: absolute;
			right: 0;
			top: 32rpx;
			width: 32rpx;
			height: 32rpx;
		}

	}

	.prizeDraw_top_title {
		width: 100%;
		height: 80rpx;
		font-size: 28rpx;
		color: #464C5B;
		text-align: left;
		font-weight: 500;
		line-height: 80rpx;
	}

	.prizeDraw_user_item {
		width: 100%;
		// height: 310rpx;
		background: #F6F9FF;
		border-radius: 8rpx;
		margin-bottom: 20rpx;
	}

	.prizeDraw_user_item_top {
		width: 100%;
		height: 80rpx;
		border-bottom: 1rpx solid #D7DDE4;
		display: flex;
		justify-content: flex-start;
		padding: 0 24rpx;
		box-sizing: border-box;
		align-items: center;
		font-size: 24rpx;
		color: #fff;

		.prizeDraw_user_item_top_left_btn_one {
			width: 104rpx;
			height: 46rpx;
			background: #00C795;
			border-radius: 8rpx;
			line-height: 46rpx;
			text-align: center;
			margin-right: 16rpx;

		}

		.prizeDraw_user_item_top_left_btn_one_act {
			background: #BFBFBF;
		}

		.prizeDraw_user_item_top_left_btn_two {
			min-width: 128rpx;
			height: 46rpx;
			background: #2B9CFF;
			border-radius: 8rpx;
			padding: 0 16rpx;
			box-sizing: border-box;
			line-height: 46rpx;
			margin-right: 16rpx;
		}

		.prizeDraw_user_item_top_left_btn_two_act {
			background: #FF5A5F;
		}

		.prizeDraw_user_item_top_title {
			width: 360rpx;
			color: #464C5B;
			text-align: left
		}

	}

	.prizeDraw_items_cont_items {
		display: flex;
		align-items: center;
		justify-content: space-between;
		height: 40rpx;
		margin-top: 20rpx;
		padding: 0 24rpx;
		box-sizing: border-box;
		font-size: 24rpx;

		color: #8C8C8C;

		.prizeDraw_items_cont_items_left {
			width: 100%;
			display: flex;
			align-items: center;


			.color_blue {
				color: #295EFF;
			}

			.prizeDraw_items_cont_items_left_a {
				color: #464C5B;

			}

			.prizeDraw_items_cont_items_cont {
				width: 480rpx;
				text-align: left;
				color: #464C5B;
			}

		}

		.timeCont {
			min-width: 380rpx;

		}

		.textRight {
			text-align: right;
			justify-content: flex-end;

		}

	}

	.prizeDraw_items_cont_items_btn {
		height: 80rpx;
		display: flex;
		align-items: center;
		justify-content: flex-end;
		padding: 0 20rpx;
		box-sizing: border-box;

		image {
			width: 28rpx;
			height: 28rpx;
		}

		.prizeDraw_items_cont_items_btn_text {
			width: 96rpx;
			height: 34rpx;
			font-family: PingFangSC, PingFang SC;
			font-weight: 400;
			font-size: 24rpx;
			color: #295EFF;
			line-height: 34rpx;
			text-align: left;
			font-style: normal;
			margin-left: 12rpx;

		}
	}

	.zj_red_btn {
		width: 750rpx;
		height: 166rpx;
		background: #fff;
		display: flex;
		align-items: center;
		justify-content: center;
		position: fixed;
		padding-bottom: 74rpx;
		bottom: 0;
		left: 0;

		.zj_red_btn_cont {
			width: 552rpx;
			height: 80rpx;
			background: #295FFF;
			border-radius: 46rpx;
			font-size: 32rpx;
			color: #fff;
			line-height: 80rpx;
		}
	}


}
</style>